package game;

//opretter klassen Player og 3 variabler
public class Player { 

	private Account	account;
	private int			position;
	private String		name;
	private int			turnsInJail = 0;
	private int			timesPassedStart = 0;
	private boolean	isGameOver = false;
	
	//Konstruerer en initialiserings værdi til Player
	public Player(String name){
		account		= new Account();
		position		= 1;
		this.name	= name;
	}
	
	public Account getAccount(){
		return account;
	}
	
	public String getName(){
		return name;
	}
	
	// Spillleren flyttes og position udregnes.
	public void movePlayer(int diceSum){
				
		int numberOfFields = Board.fields.length;
		
		
		if((position + diceSum) >= (numberOfFields*2)) { //For hvis diceSum er et åndsvagt højt tal.
			if(((position + diceSum) % numberOfFields) == 0){
				position = 1;
			} else {
				position = position + (diceSum % numberOfFields);
			}
			
		} else if ((position + diceSum) <= numberOfFields){
			position = position + diceSum;
			
		}
		else{
			position = position + diceSum - numberOfFields;
			passStart();
			
		}
	}
	
	public int getPosition(){
		return position;
	}
	
	public void setPosition(int moveToPosition){
		if(moveToPosition ==10){
			position = moveToPosition;
		}
		else if((moveToPosition >= 0) && (moveToPosition < 40) ){
			if(moveToPosition < position){
				passStart();
			}
			position = moveToPosition;
		}
	}
	
	public void passStart(){
		timesPassedStart++;
		getAccount().addPoints(4000);
	}
	
	public int getTurnsInJail(){
		return turnsInJail;
	}
	
	public void setTurnsInJail(int turnsInJail){
		this.turnsInJail = turnsInJail;
	}
	
	public void setGameOver()
	{
		isGameOver = true;
	}
	
	public boolean getGameOver()
	{
		return isGameOver;
	}
	public int getTimesPassedStart(){
	return timesPassedStart;
	}
}